#include "shm.hpp"
#include <unistd.h>
#include <cassert>
#include <sys/stat.h>
#include <sys/types.h>
using namespace std;
int main()
{
    umask(0);
    //1.创建共享内存的名字(标识符用以区分)
    key_t k=ftok(pathname,proj_id);
    //2.创建共享内存
    int shmid=shmget(k,4096,IPC_CREAT|IPC_EXCL|0666);
    assert(shmid>=0);
    //3.使当前进程与共享内存联系起来
    char* address=(char*)shmat(shmid,nullptr,0);
    assert(address);
    char c='A';
    sleep(5);
    for(int i=0;i<26;i++)
    {
        address[i]=c+i;
        address[i+1]='\0';
        sleep(1);
    }
    //4.与共享内存脱离
    shmdt(address);
    sleep(30);
    //5.删除共享内存
    shmctl(shmid,IPC_RMID,nullptr);

    return 0;
}